//  [9/3/2013 OMEGA] created

#ifndef _DUELASSEGROUPVIEW_H_
#define _DUELASSEGROUPVIEW_H_

#include <QTreeView>
#include <QItemDelegate>
#include <QMenu>
#include "DuelAssECommon.h"
#include "DuelAssEGroupModel.h"
#include "DuelAssENameGenerator.h"
#include "DuelAssENoFocusDelegate.h"

class DAssEGroupView;
class DAssEGroupItemDelegate : public QItemDelegate
{
	Q_OBJECT
public:
	DAssEGroupItemDelegate(DAssEGroupView* parent);
	QWidget*	createEditor(QWidget *parent, const QStyleOptionViewItem &/* option */,  
		const QModelIndex &/* index */) const;  
	void		setEditorData(QWidget *editor,  
		const QModelIndex &index) const; 
	void		setModelData(QWidget *editor, QAbstractItemModel *model,  
		const QModelIndex &index) const;;
protected:
	DAssEGroupView*	mParentView;
};


class DAssEGroupView : public QTreeView
{
	Q_OBJECT
public:
	DAssEGroupView(DuelAssetEditor* parent);
	virtual ~DAssEGroupView();
	
	void		contextMenuEvent( QContextMenuEvent * event );

signals:
	void		removeGroupEnable(bool flag);

public slots:


	void		onProjectLoaded(DAssEProject* proj);
	void		onProjectUnloaded();

		// override : QAbstractItemModel---------
	void		selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);

	// used receive signals of add group/remove group.
	void		addGroup();
	void		removeSelectedGroup();
	// provide interface for the delegate. don't call it yourself.
	void		renameGroup(const QString& oldName, const QString& newName);

	void		editArchivesInGroup();
	void		declareResource();

	// receive signals from DuelAsssetEditor.
	void		onGroupAdded(DAssEGroup* grp, bool isNew);
	void		onGroupRemoved(DAssEGroup* grp);
	void		onGroupRenamed(const QString& oldGrpName, const QString& newGrpName);

	void		onArchiveAttachedToGroup(DAssEGroup* grp, DAssEArchive* arch);
	void		onArchiveDetachedFromGroup(DAssEGroup* grp, DAssEArchive* arch);
private:
	DAssEGroupItemDelegate	mDelegate;
	DuelAssetEditor*		mParent;
	DAssEWorkbench*			mWorkbench;
	DAssEGroupModel			mModel;
	DAssENameGenerator		mGroupNameGen;
	QMenu					mPopupMenu;
	NoFocusDelegate			mItemDelegate;
	
};

#endif